(library (math)
  (export circular-remainder
          next-in-circle
          previous-in-circle)
  (import
   (except (rnrs base) error)
   (only (guile)
         lambda* λ
         remainder)))


(define circular-remainder
  (λ (num mod)
    "Return the circular remainder of the division of NUM by
MOD."
    (remainder (+ num mod) mod)))


(define next-in-circle
  (λ (num circle-length)
    "Return the next number in the circle."
    (circular-remainder (+ num 1) circle-length)))


(define previous-in-circle
  (λ (num circle-length)
    "Return the next number in the circle."
    (circular-remainder (- num 1) circle-length)))
